﻿using System;
using Samplum.HostObjects;

namespace Samplum.Patches
{
	public sealed class Sine : Patch
	{
		public Sine()
		{
			Frq = 440;
			UpdateStepWidth();
		}

		private double _currentDegree;
		private double _stepWidth;

		private double _frq;
		public double Frq
		{
			get { return _frq; }
			set
			{
				_frq = value;
				UpdateStepWidth();
			}
		}

		public double Out;

		private void UpdateStepWidth()
		{
			_stepWidth = 2 * Math.PI * Frq / SampleRate;
		}

		public override void Ar()
		{
			Out = Math.Sin(_currentDegree);
			_currentDegree += _stepWidth;
		}
	}
}
